home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tvalt.exe
/
GFX.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-05
|
4KB
|
161 lines
#define Uses_TMouse
#define Uses_TEvent
#include <tv.h>
#include <graphics.h>
#define HIBYTE(x) ( ((x) >> 8) & 0xFF )
#define LOBYTE(x) ( (x) & 0xFF )
#define BGATTR(x) ( ((HIBYTE(x)) >> 4) & 0x0F )
#define FGATTR(x) ( (HIBYTE(x)) & 0x0F )
static unsigned char strbuf[100];
extern unsigned char shadowAttr;
// function: paintBkgd
// declaration:
// short paintBkgd( short ix, short iy, short max, ushort *buf );
// where:
// ix = start horizontal position (in pixels).
// iy = start vertical position (in pixels).
// max = the length of buf (in words).
// buf = the char/attr buffer.
// paintBkgd() searches buf for the maximum number of entries that have the
// same background color (up to max), then paints that background 'bar'
// to the screen at (ix,iy). It is assumed that the width and height of
// each character is 8x8 pixels. Returns the number of entries whose
// background was painted.
short paintBkgd( short ix, short iy, short max, ushort *buf )
{
uchar attr = BGATTR(*buf);
short count = 0;
while( count < max && BGATTR(buf[count]) == attr )
count++;
setfillstyle( SOLID_FILL, attr );
bar( ix, iy, ix+(count << 3)-1, iy+7 );
return count;
}
// function: paintFrgd
// declaration:
// short paintFrgd( short ix, short iy, short max, ushort *buf );
// where:
// ix = start horizontal position (in pixels).
// iy = start vertical position (in pixels).
// max = the length of buf (in words).
// buf = the char/attr buffer.
// paintFrgd() skips leading spaces in buf's char data, then searches buf
// for the maximum number of entries that have the same foreground color
// (up to max), then paints this string to the screen at (ix,iy). Returns
// the number of characters (including the leading spacing) that was
// painted.
short paintFrgd( short ix, short iy, short max, ushort *buf )
{
uchar attr;
short fat = 0, count = 0;
char *ptr = strbuf;
while( max > 0 && LOBYTE(*buf) == ' ' )
{
max--;
buf++;
ix += 8;
fat++;
}
attr = FGATTR(*buf);
while( count < max && FGATTR(buf[count]) == attr )
{
*ptr = LOBYTE(buf[count]);
if( *ptr == ' ' ) break;
ptr++;
count++;
}
*ptr = 0;
setcolor(attr);
outtextxy( ix, iy, strbuf );
return count+fat;
}
// function: altWriteMethod
// declaration:
// void altWriteMethod( short x, short y, short wid, ushort *buf,
// short sflag );
// where:
// x = start horizontal position (in chars) : 0-based.
// y = start vertical position (in chars) : 0-based.
// wid = the length of buf (in words).
// buf = the char/attr buffer.
// sflag = 0 if the attr entries of buf should be used; <> 0 if
// shadowAttr (extern) should be the attribute.
// When alternative write method is enable, this function is used to write
// the TV char/attr data to the screen.
void altWriteMethod( short x, short y, short wid, ushort *buf, short sflag )
{
char *ptr = strbuf;
unsigned short far *pbuf;
short iw, count, ix, iy;
// Its a little involved to ensure that the mouse cursor needs to be
// hidden - and the slowness of this graphics writing doesn't ensure
// that the mouse won't move into the paint region while we're writing
// so I just hide it every time.
TMouse::hide();
// Paint the background colors.
if( !sflag ) // use the attribute data in buf.
{
pbuf = buf;
iw = wid;
ix = x << 3;
iy = y << 3;
while( iw > 0 )
{
count = paintBkgd( ix, iy, iw, pbuf );
ix += (count << 3);
pbuf += count;
iw -= count;
}
}
else // use shadowAttr attribute.
{
setfillstyle( SOLID_FILL, (shadowAttr >> 4) );
bar( x << 3, y << 3, ((x+wid-1) << 3)-1, ((y+1) << 3)-1 );
}
// Paint the foreground characters.
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( LEFT_TEXT, TOP_TEXT );
if( !sflag ) // use the attribute data in buf.
{
pbuf = buf;
iw = wid;
ix = x << 3;
iy = y << 3;
while( iw > 0 )
{
count = paintFrgd( ix, iy, iw, pbuf );
ix += (count << 3);
pbuf += count;
iw -= count;
}
}
else // use shadowAttr attribute.
{
for( count = 0; count < wid; count++ )
*ptr++ = LOBYTE(buf[count]);
*ptr = 0;
setcolor( shadowAttr & 0x0F );
outtextxy( x << 3, (y << 3), strbuf );
}
// Restore the mouse.
TMouse::show();
}